{include file="public/head" /}
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">权限管理</a>
            <a href="">后台用户管理</a>
            <a>
              <cite>用户列表</cite></a>
          </span>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="开始日"
                                   name="start" id="start" value="{$search.start?$search.start:''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="截止日"
                                   name="end" id="end" value="{$search.end?$search.end:''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off"
                                   class="layui-input" value="{$search.username?$search.username:''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="nickname"  placeholder="请输入昵称" autocomplete="off"
                                   class="layui-input" value="{$search.nickname?$search.nickname:''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button  class="layui-btn layui-btn-danger {:adminAuthCheck('/Admin/delete',$routeArr)}" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn {:adminAuthCheck('/Admin/add',$routeArr)}" onclick="xadmin.open('添加用户','../Admin/add',600,400)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form" id="pagetab">
                        <thead>
                        <tr>
                            <th><input type="checkbox" name=""  lay-skin="primary"></th>
                            <th>ID</th>
                            <th>登录名</th>
                            <th>昵称</th>
                            <th>角色</th>
                            <th>加入时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                        {volist name="res" id="v"}
                        <tr>
                            <td><input type="checkbox" name=""  lay-skin="primary"></td>
                            <td>{$v.id}</td>
                            <td>{$v.username}</td>
                            <td>{$v.nickname}</td>
                            <td>{:getName("role",$v['role_ids'],"nickname")}</td>
                            <td>{:date('Y-m-d', $v['createdate'])}</td>
                            <td class="td-status">
                                {eq name="v.status" value="1"}
                                <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                {/eq}
                                {eq name="v.status" value="2"}
                                <span class="layui-btn layui-btn-danger layui-btn-mini">已禁用</span>
                                {/eq}
                            </td>
                            <td class="td-manage">
                                {eq name="v.status" value="1"}
                                <span onclick="member_stop(this,{$v.id})"
                                      class="layui-btn layui-btn-normal layui-btn-mini st_se {:adminAuthCheck('/Admin/status',$routeArr)}">禁用</span>
                                <input type="hidden" id="{$v.id}_s" value="2" />
                                {/eq}
                                {eq name="v.status" value="2"}
                                <span onclick="member_stop(this,{$v.id})"
                                      class="layui-btn layui-btn-normal layui-btn-mini st_se {:adminAuthCheck('/Admin/status',$routeArr)}">启用</span>
                                <input type="hidden" id="{$v.id}_s" value="1" />
                                {/eq}
                                <span onclick="xadmin.open('编辑','../admin/update/id/{$v.id}', 720, 650)"
                                      class="layui-btn layui-btn-group layui-btn-mini {:adminAuthCheck('/Admin/update',$routeArr)}">编辑</span>
                                <span onclick="member_del(this,{$v.id})"
                                      class="layui-btn layui-btn-danger layui-btn-mini {:adminAuthCheck('/Admin/delete',$routeArr)}">删除</span>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page" id="page"></div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form', 'laypage'], function(){
        var laydate = layui.laydate;
        var laypage = layui.laypage;
        var form = layui.form;
        var url = '{:url("../Admin/index")}'+'?{$query}';
        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            type: "datetime",
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#end', //指定元素
            type: "datetime",
        });
        //执行一个laypage实例
        laypage.render({
            elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
            ,count:'{$count}'//数据总数，从服务端得到
            ,limit :'{$pageTotal}'
            ,curr:'{$curr}'
            ,jump: function(obj, first){
                if(!first){ //一定要加此判断，否则初始时会无限刷新
                    location.href = url+'&page='+obj.curr;
                }
            }
        });
    });

    /*用户-停用*/
    function member_stop(obj,id){
        var str = '';
        var is_close = $('#'+id+'_s').val();
        if(is_close == 2){
            str = '确认要禁用吗？';
        } else {
            str = '确认要启用吗？';
        }
        layer.confirm(str,function(index){
            $.ajax({
                type: "POST",
                url: "{:getUrl()}Admin/status",
                data: {id:id,status:is_close},
                dataType: "json",
                success: function(data){
                    if(data.code > 0)
                    {
                        if(is_close == 2) {
                            $('#'+id+'_s').val(1);
                            //发异步把用户状态进行更改
                            $(obj).attr('title','禁用')
                            $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-normal');
                            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-danger').html('已禁用');
                            $(obj).parents("tr").find(".td-manage").find('.st_se').html('启用');
                            layer.msg('已停用!',{icon: 5,time:1000});
                        } else {
                            $('#'+id+'_s').val(2);
                            $(obj).attr('title','启用')
                            $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-danger');
                            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-normal').html('已启用');
                            $(obj).parents("tr").find(".td-manage").find('.st_se').html('禁用');
                            layer.msg('已启用!',{icon: 6,time:1000});
                        }
                    } else {
                        layer.msg(data.msg,{icon: 5,time:1000});
                    }
                }
            });
        });
    }

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: "POST",
                url: "{:getUrl()}Admin/delete",
                data: {id:id,class:'admin'},
                dataType: "json",
                success: function(data){
                    if(data.code > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    } else {
                        layer.msg(data.msg,{icon: 5,time:1000});
                    }
                }
            });
        });
    }
    function delAll(argument){
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</html>
